﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebSite
{
    public partial class UplodFiles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string outmessage = string.Empty;
            System.Web.HttpFileCollection FileLists = System.Web.HttpContext.Current.Request.Files;
            //System.Web.HttpPostedFile hfc = Request.Files[0];
            for (int i = 0; i < FileLists.Count; i++)
            {
                outmessage += "文件总数:" + FileLists.Count.ToString() + "<BR />";
                outmessage += FileLists[i].FileName + ";Size=";
                outmessage += FileLists[i].ContentLength.ToString() + "<BR />";

                HttpPostedFile postfile = FileLists[i];
                byte[] buffer = new byte[postfile.InputStream.Length];
                postfile.InputStream.Read(buffer, 0, buffer.Length);

                System.IO.FileStream fs = new System.IO.FileStream(@"c:\test.doc", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                fs.Write(buffer, 0, buffer.Length);
                fs.Flush();
                fs.Close();
            }
            outmessage += "querystring:" + Request.QueryString.Keys.Count.ToString();
            outmessage += "form:" + Request.Form.Keys.Count.ToString();
            for (int i = 0; i < HttpContext.Current.Request.Form.Keys.Count; i++)
            {

                outmessage += Request.Form.Keys[i].ToString() + ":" + Request.Form[i];
                outmessage += "AllKeys" + Request.Form.AllKeys.ToString();
            }
            lbMessage.Text = outmessage;

            //Response.Write(HttpContext.Current.Request.QueryString[0]);
            //Response.Write(HttpContext.Current.Request.QueryString[1]);
        }
    }
}
